package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.LogiCustomerCheckBillBo;
import com.piggy.logi.sys.bo.LogiCustomerCheckBillQueryBo;
import com.piggy.logi.sys.service.ILogiCustomerCheckBillService;
import com.piggy.logi.sys.vo.LogiCustomerCheckBillRecordVo;
import com.piggy.logi.sys.vo.LogiCustomerCheckBillVo;
import com.piggy.logi.sys.vo.LogiCustomerWayBillVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户对账Controller
 *
 * @author fengxy
 * @date 2023/10/17 21:28
 **/
@Api(value = "客户对账控制器", tags = {"客户对账"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/customer/checkBill")
public class LogiCustomerCheckBillController extends BaseController {

    private final ILogiCustomerCheckBillService iLogiCustomerCheckBillService;

    /**
     * 查询客户对账列表
     */
    @ApiOperation("查询客户对账列表")
    //@SaCheckPermission("sys:waybill:checkBill:list")
    @PostMapping("/list")
    public TableDataInfo<LogiCustomerCheckBillVo> list(@Validated @RequestBody LogiCustomerCheckBillQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCustomerCheckBillService.queryPageList(bo);
    }

    /**
     * 获取客户对账详情
     */
    @ApiOperation("获取客户对账详情")
    //@SaCheckPermission("sys:waybill:checkBill:query")
    @PostMapping("/query")
    public R<LogiCustomerCheckBillVo> query(@Validated @RequestBody LogiCustomerCheckBillBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return R.ok(iLogiCustomerCheckBillService.queryInfo(bo));
    }

    /**
     * 获取客户对账记录详情
     */
    @ApiOperation("获取客户对账记录详情")
    //@SaCheckPermission("sys:waybill:checkBill:recordInfo")
    @PostMapping("/record")
    public R<LogiCustomerCheckBillRecordVo> recordInfo(@Validated @RequestBody LogiCustomerCheckBillBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return R.ok(iLogiCustomerCheckBillService.recordInfo(bo));
    }

    /**
     * 查询对账运单列表
     */
    @ApiOperation("查询对账运单列表")
    //@SaCheckPermission("sys:waybill:checkBill:wayBillList")
    @PostMapping("/wayBillList")
    public TableDataInfo<LogiCustomerWayBillVo> wayBillList(@Validated @RequestBody LogiCustomerCheckBillBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiCustomerCheckBillService.wayBillList(bo);
    }

    /**
     * 确认对账
     **/
    @ApiOperation("确认对账")
    //@SaCheckPermission("sys:waybill:checkBill:confirmCheck")
    @LogiLog(title = "客户对账", businessType = BusinessType.UPDATE)
    @PostMapping("/confirmCheck")
    public R<Object> confirmCheck(@Validated @RequestBody LogiCustomerCheckBillBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        iLogiCustomerCheckBillService.confirmCheck(bo);
        return R.ok();
    }

    /**
     * 取消对账
     **/
    @ApiOperation("取消对账")
    //@SaCheckPermission("sys:waybill:checkBill:cancelCheck")
    @LogiLog(title = "客户对账", businessType = BusinessType.UPDATE)
    @PostMapping("/cancelCheck")
    public R<Object> cancelCheck(@Validated @RequestBody LogiCustomerCheckBillBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        iLogiCustomerCheckBillService.cancelCheck(bo);
        return R.ok();
    }

    /**
     * 发送邮件
     **/
    @ApiOperation("发送邮件")
    //@SaCheckPermission("sys:waybill:checkBill:sendEmail")
    @LogiLog(title = "客户对账", businessType = BusinessType.OTHER)
    @PostMapping("/sendEmail")
    public R<Object> sendEmail(@Validated @RequestBody LogiCustomerCheckBillBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        iLogiCustomerCheckBillService.sendEmail(bo);
        return R.ok();
    }
}
